layui.use(['form','layer',],function (){
    let form = layui.form,layer = layui.layer;
})


/**
 * @author: ChengJW
 * @params:
 * @return:
 * @date: 2021/11/11
 * @description: 放弃按钮
 */
function quituUpdateUserPassword() {
    //获取当前弹窗的索引，并关闭；parent 是 layui 定义的全局变量
    let index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}

/**
 * @author: ChengJW
 * @params:
 * @return:
 * @date: 2021/11/11
 * @description: 新增用户信息
 */
function updateUserPassword() {
    //旧密码
    let oldPswd = $("#oldPswd").val().trim();
    //新密码
    let newPswd = $("#newPswd").val().trim();
    //确认新密码
    let checkPswd = $("#checkPswd").val().trim();

    if (valueIsEmpty(oldPswd) || valueIsEmpty(newPswd) || valueIsEmpty(checkPswd)){
        layer.msg("密码不能为空!",{icon:0,time: 1500});
        return;
    }
    if (!valueIsEqual(newPswd,checkPswd)){
        layer.msg("两次密码输入不一致!",{icon:0,time: 1500});
        return;
    }
    if (valueIsEqual(oldPswd,newPswd)){
        layer.msg("新密码不能与旧密码相同!",{icon:0,time: 1500});
        return;
    }
    let pswdJsonData = {
        "urPwd" : oldPswd,
        "urNewPwd" : newPswd
    }
    sendAjax("/userinfo/updatePassword/updatePswd",pswdJsonData,function (result){
        if (valueIsEqual(result.code,"00")){
            top.layui.layer.alert('更改密码之后，请您重新登录',{closeBtn:0},function (){
                sendAjax("/index/logout",null,function (result) {
                    let userinfo = result.data;
                    if (valueIsEqual(result.code,"00")){
                        top.window.location.href = "/login";
                    }else if (valueIsEqual(result.code,"01")){
                        layer.alert("退出失败，请稍后再试",{icon:3,title:'Notice'});
                    }
                });
            });
        }else if (valueIsEqual(result.code,"02")){
            top.layer.msg(result.data,{icon:5,time: 1500});
        }
    });
}





